<?php
require_once dirname(__FILE__) . '/common/common.inc.php';
require_once dirname(__FILE__) . "/database/$database/database.inc.php";

header('Content-Type: text/plain');

global $myManager;

$orm1 = classToOrm('pz_model');
$orm2 = classToOrm('pz_model_state');
$orm3 = classToOrm('pz_model_transition');

if ($orm1 && $orm2 && $orm3) {
  try {
    $myManager->start_t();
    $models = array();
    $model1 = new stdClass();
    $model1->track_id = MiscUtils::unique();
    $model1->name = 'Sample';
    $model2 = new stdClass();
    $model2->track_id = MiscUtils::unique();
    $model2->name = 'Mail';
    $model3 = new stdClass();
    $model3->track_id = MiscUtils::unique();
    $model3->name = 'Personal';
    array_push($models, $model1, $model2, $model3);
    
    $states = array();
    $s1 = new stdClass();
    $s1->track_id = MiscUtils::unique();
    $s1->model_id = 1;
    $s1->name = '签收光盘';
    
    $s2 = new stdClass();
    $s2->track_id = MiscUtils::unique();
    $s2->model_id = 1;
    $s2->name = '备份光盘';
    
    $s3 = new stdClass();
    $s3->track_id = MiscUtils::unique();
    $s3->model_id = 1;
    $s3->name = '给片子评分';
    
    $s4 = new stdClass();
    $s4->track_id = MiscUtils::unique();
    $s4->model_id = 1;
    $s4->name = '暂不挑片';
    
    $s5 = new stdClass();
    $s5->track_id = MiscUtils::unique();
    $s5->model_id = 1;
    $s5->name = '挑选片子';
    
    $s6 = new stdClass();
    $s6->track_id = MiscUtils::unique();
    $s6->model_id = 1;
    $s6->name = '审核片子';
    
    $s7 = new stdClass();
    $s7->track_id = MiscUtils::unique();
    $s7->model_id = 1;
    $s7->name = '暂不修片';
    
    $s8 = new stdClass();
    $s8->track_id = MiscUtils::unique();
    $s8->model_id = 1;
    $s8->name = '整理片子并挑选设计师';
    
    $s9 = new stdClass();
    $s9->track_id = MiscUtils::unique();
    $s9->model_id = 1;
    $s9->name = '完成修片并上传';
    
    $s10 = new stdClass();
    $s10->track_id = MiscUtils::unique();
    $s10->model_id = 1;
    $s10->name = '给片子排序';
    
    $s11 = new stdClass();
    $s11->track_id = MiscUtils::unique();
    $s11->model_id = 1;
    $s11->name = '安排撰文';
    
    $s12 = new stdClass();
    $s12->track_id = MiscUtils::unique();
    $s12->model_id = 1;
    $s12->name = '收到撰文';
    
    $s13 = new stdClass();
    $s13->track_id = MiscUtils::unique();
    $s13->model_id = 1;
    $s13->name = '发布片子';
    
    $s14 = new stdClass();
    $s14->track_id = MiscUtils::unique();
    $s14->model_id = 1;
    $s14->name = '确认发片';
    
    $s15 = new stdClass();
    $s15->track_id = MiscUtils::unique();
    $s15->model_id = 1;
    $s15->name = '发布完成';
    
    $s16 = new stdClass();
    $s16->track_id = MiscUtils::unique();
    $s16->model_id = 2;
    $s16->name = '签收包裹';
    
    $s17 = new stdClass();
    $s17->track_id = MiscUtils::unique();
    $s17->model_id = 2;
    $s17->name = '包裹已签收';
    
    $s18 = new stdClass();
    $s18->track_id = MiscUtils::unique();
    $s18->model_id = 3;
    $s18->name = 'New Task';
    
    $s19 = new stdClass();
    $s19->track_id = MiscUtils::unique();
    $s19->model_id = 3;
    $s19->name = 'Questioned';
    
    $s20 = new stdClass();
    $s20->track_id = MiscUtils::unique();
    $s20->model_id = 3;
    $s20->name = 'Reopened';
    
    $s21 = new stdClass();
    $s21->track_id = MiscUtils::unique();
    $s21->model_id = 3;
    $s21->name = 'Task is completed';
    
    $s22 = new stdClass();
    $s22->track_id = MiscUtils::unique();
    $s22->model_id = 3;
    $s22->name = 'Task is comfirmed';

    array_push($states, $s1, $s2, $s3, $s4, $s5, $s6, $s7, $s8, $s9, $s10, $s11, $s12, $s13, $s14, $s15, $s16, $s17, $s18, $s19, $s20, $s21, $s22);
    
    $transitions = array();
    $t0 = new stdClass();
    $t0->track_id = MiscUtils::unique();
    $t0->model_id = 1;
    $t0->source_id = 1;
    $t0->target_id = 2;
    $t0->name = '签收';
    $t0->user_type = '';
    $t0->day = 3;
    
    $t1 = new stdClass();
    $t1->track_id = MiscUtils::unique();
    $t1->model_id = 1;
    $t1->source_id = 2;
    $t1->target_id = 3;
    $t1->name = '备份';
    $t1->user_type = USER_TYPE_ASSISTANT;
    $t1->day = 3;
    
    $t2 = new stdClass();
    $t2->track_id = MiscUtils::unique();
    $t2->model_id = 1;
    $t2->source_id = 3;
    $t2->target_id = 5;
    $t2->name = '评片';
    $t2->user_type = USER_TYPE_ASSISTANT;
    $t2->day = 3;
    
    $t3 = new stdClass();
    $t3->track_id = MiscUtils::unique();
    $t3->model_id = 1;
    $t3->source_id = 5;
    $t3->target_id = 6;
    $t3->name = '挑片';
    $t3->user_type = USER_TYPE_ASSISTANT;
    $t3->day = 3;
    
    $t4 = new stdClass();
    $t4->track_id = MiscUtils::unique();
    $t4->model_id = 1;
    $t4->source_id = 6;
    $t4->target_id = 8;
    $t4->name = '评审';
    $t4->user_type = USER_TYPE_ADMINISTER;
    $t4->day = 3;
    
    $t5 = new stdClass();
    $t5->track_id = MiscUtils::unique();
    $t5->model_id = 1;
    $t5->source_id = 8;
    $t5->target_id = 9;
    $t5->name = '挑选设计师';
    $t5->user_type = USER_TYPE_ASSISTANT;
    $t5->day = 3;
    
    $t6 = new stdClass();
    $t6->track_id = MiscUtils::unique();
    $t6->model_id = 1;
    $t6->source_id = 9;
    $t6->target_id = 10;
    $t6->name = '上传';
    $t6->user_type = USER_TYPE_DESIGNER;
    $t6->day = 3;
    
    $t7 = new stdClass();
    $t7->track_id = MiscUtils::unique();
    $t7->model_id = 1;
    $t7->source_id = 10;
    $t7->target_id = 11;
    $t7->name = '完成排序';
    $t7->user_type = USER_TYPE_ADMINISTER;
    $t7->day = 3;
    
    $t8 = new stdClass();
    $t8->track_id = MiscUtils::unique();
    $t8->model_id = 1;
    $t8->source_id = 11;
    $t8->target_id = 12;
    $t8->name = '安排';
    $t8->user_type = USER_TYPE_ASSISTANT;
    $t8->day = 3;
    
    $t9 = new stdClass();
    $t9->track_id = MiscUtils::unique();
    $t9->model_id = 1;
    $t9->source_id = 12;
    $t9->target_id = 13;
    $t9->name = '收取';
    $t9->user_type = USER_TYPE_ASSISTANT;
    $t9->day = 3;
    
    $t100 = new stdClass();
    $t100->track_id = MiscUtils::unique();
    $t100->model_id = 1;
    $t100->source_id = 13;
    $t100->target_id = 14;
    $t100->name = '发片';
    $t100->user_type = USER_TYPE_ASSISTANT;
    $t100->day = 3;
    
    $t10 = new stdClass();
    $t10->track_id = MiscUtils::unique();
    $t10->model_id = 1;
    $t10->source_id = 14;
    $t10->target_id = 15;
    $t10->name = '确认';
    $t10->user_type = USER_TYPE_ADMINISTER;
    $t10->day = 999;
    
    $t11 = new stdClass();
    $t11->track_id = MiscUtils::unique();
    $t11->model_id = 2;
    $t11->source_id = 16;
    $t11->target_id = 17;
    $t11->name = '签收';
    $t11->user_type = '';
    $t11->day = 999;

    $t12 = new stdClass();
    $t12->track_id = MiscUtils::unique();
    $t12->model_id = 1;
    $t12->source_id = 4;
    $t12->target_id = 3;
    $t12->name = '返回';
    $t12->user_type = USER_TYPE_ASSISTANT;
    $t12->day = 3;
    
    $t13 = new stdClass();
    $t13->track_id = MiscUtils::unique();
    $t13->model_id = 1;
    $t13->source_id = 7;
    $t13->target_id = 6;
    $t13->name = '撤销';
    $t13->user_type = USER_TYPE_ADMINISTER;
    $t13->day = 3;
    
    $t14 = new stdClass();
    $t14->track_id = MiscUtils::unique();
    $t14->model_id = 3;
    $t14->source_id = 18;
    $t14->target_id = 21;
    $t14->name = 'Done';
    $t14->user_type = '';
    $t14->day = 3;
    
    $t15 = new stdClass();
    $t15->track_id = MiscUtils::unique();
    $t15->model_id = 3;
    $t15->source_id = 18;
    $t15->target_id = 19;
    $t15->name = 'Ask';
    $t15->user_type = '';
    $t15->day = 3;
    
    $t16 = new stdClass();
    $t16->track_id = MiscUtils::unique();
    $t16->model_id = 3;
    $t16->source_id = 19;
    $t16->target_id = 20;
    $t16->name = 'Answer';
    $t16->user_type = '';
    $t16->day = 3;
    
    $t17 = new stdClass();
    $t17->track_id = MiscUtils::unique();
    $t17->model_id = 3;
    $t17->source_id = 20;
    $t17->target_id = 21;
    $t17->name = 'Done';
    $t17->user_type = '';
    $t17->day = 3;
    
    $t18 = new stdClass();
    $t18->track_id = MiscUtils::unique();
    $t18->model_id = 3;
    $t18->source_id = 20;
    $t18->target_id = 19;
    $t18->name = 'Ask';
    $t18->user_type = '';
    $t18->day = 3;
    
    $t19 = new stdClass();
    $t19->track_id = MiscUtils::unique();
    $t19->model_id = 3;
    $t19->source_id = 21;
    $t19->target_id = 22;
    $t19->name = 'Confirm';
    $t19->user_type = '';
    $t19->day = 999;
    
    array_push($transitions, $t0, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t100, $t10, $t11, $t12, $t13, $t14, $t15, $t16, $t17, $t18, $t19);
    
    foreach($models as &$model) {
      $orm1->add($myManager, $model);
    }
    
    foreach($states as &$state) {
      $orm2->add($myManager, $state);
    }
    foreach($transitions as &$transition) {
      $orm3->add($myManager, $transition);
    }
    
    $myManager->commit_t();

    echo json_encode(array());
  } catch (PDOException $e) {
    echo $e->getMessage();
  }
}
?>